package com.bw.goods.mvvm.bind;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.databinding.BindingAdapter;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.bw.goods.R;
import com.bw.goods.mvvm.model.entity.HomeGoodsEntity;
import com.bw.mvvm_comom.BaseApplication;
import com.bw.mvvm_comom.network.load.LoadImage;
import com.chad.library.adapter.base.BaseQuickAdapter;

public class HomeValueBind {
    @BindingAdapter(value = {"valueadapter","entity"},requireAll = false)
    public static void valueRVBind(RecyclerView recyclerView,
                                   BaseQuickAdapter adapter,
                                   HomeGoodsEntity.DataBean entity){
        BaseQuickAdapter baseQuickAdapter = (BaseQuickAdapter) recyclerView.getAdapter();
        if (baseQuickAdapter == null) {
            GridLayoutManager manager = new GridLayoutManager(recyclerView.getContext(), 2);
            manager.setOrientation(GridLayoutManager.VERTICAL);
            recyclerView.setLayoutManager(manager);
            View view = LayoutInflater.from(recyclerView.getContext())
                    .inflate(R.layout.view_homevalue, null);
            ImageView img = view.findViewById(R.id.value_head_img);
            TextView title = view.findViewById(R.id.value_head_title);
            TextView dec = view.findViewById(R.id.value_head_dec);
            SharedPreferences sj = BaseApplication.getApplication().getSharedPreferences("sj", Context.MODE_PRIVATE);
            String title1 = sj.getString("title", "12");
            String img1 = sj.getString("img", "");
            String dec1 = sj.getString("dec", "");
            LoadImage.loadMatchImg(img1,img);
            title.setText(title1);
            dec.setText(dec1);
            adapter.setHeaderView(view);
            recyclerView.setAdapter(adapter);
        }
    }
}
